package com.puti.doctor.service.impl;

import java.util.List;

import com.puti.common.core.domain.R;
import com.puti.doctor.domain.HospitalDoctorInfo;
import com.puti.doctor.mapper.HospitalDoctorInfoMapper;
import com.puti.doctor.service.IHospitalDoctorInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.puti.doctor.domain.Result;
import com.puti.doctor.domain.ResultCode;

/**
 * 医院-医生-个人信息 医院-医生-个人信息Service业务层处理
 *
 * @author puti
 * @date 2021-04-21
 */
@Service
public class HospitalDoctorInfoServiceImpl implements IHospitalDoctorInfoService
{
    @Autowired
    private HospitalDoctorInfoMapper hospitalDoctorInfoMapper;

    /**
     * 查询医院-医生-个人信息 医院-医生-个人信息
     *
     * @param doctorId 医院-医生-个人信息 医院-医生-个人信息ID
     * @return 医院-医生-个人信息 医院-医生-个人信息
     */
    @Override
    public HospitalDoctorInfo selectHospitalDoctorInfoById(Long doctorId)
    {
        return hospitalDoctorInfoMapper.selectHospitalDoctorInfoById(doctorId);
    }

    /**
     * 查询医院-医生-个人信息 医院-医生-个人信息列表
     *
     * @param hospitalDoctorInfo 医院-医生-个人信息 医院-医生-个人信息
     * @return 医院-医生-个人信息 医院-医生-个人信息
     */
    @Override
    public List<HospitalDoctorInfo> selectHospitalDoctorInfoList(HospitalDoctorInfo hospitalDoctorInfo)
    {
        return hospitalDoctorInfoMapper.selectHospitalDoctorInfoList(hospitalDoctorInfo);
    }

    /**
     * 新增医院-医生-个人信息 医院-医生-个人信息
     *
     * @param hospitalDoctorInfo 医院-医生-个人信息 医院-医生-个人信息
     * @return 结果
     */
    @Override
    public int insertHospitalDoctorInfo(HospitalDoctorInfo hospitalDoctorInfo)
    {
        return hospitalDoctorInfoMapper.insertHospitalDoctorInfo(hospitalDoctorInfo);
    }

    /**
     * 修改医院-医生-个人信息 医院-医生-个人信息
     *
     * @param hospitalDoctorInfo 医院-医生-个人信息 医院-医生-个人信息
     * @return 结果
     */
    @Override
    public int updateHospitalDoctorInfo(HospitalDoctorInfo hospitalDoctorInfo)
    {
        return hospitalDoctorInfoMapper.updateHospitalDoctorInfo(hospitalDoctorInfo);
    }

    /**
     * 批量删除医院-医生-个人信息 医院-医生-个人信息
     *
     * @param doctorIds 需要删除的医院-医生-个人信息 医院-医生-个人信息ID
     * @return 结果
     */
    @Override
    public int deleteHospitalDoctorInfoByIds(Long[] doctorIds)
    {
        return hospitalDoctorInfoMapper.deleteHospitalDoctorInfoByIds(doctorIds);
    }

    /**
     * 删除医院-医生-个人信息 医院-医生-个人信息信息
     *
     * @param doctorId 医院-医生-个人信息 医院-医生-个人信息ID
     * @return 结果
     */
    @Override
    public int deleteHospitalDoctorInfoById(Long doctorId)
    {
        return hospitalDoctorInfoMapper.deleteHospitalDoctorInfoById(doctorId);
    }

    @Override
    public R loginDoctor(HospitalDoctorInfo hospitalDoctorInfo) {
        List<HospitalDoctorInfo> hospitalDoctorInfos = hospitalDoctorInfoMapper.loginDoctor(hospitalDoctorInfo);
        HospitalDoctorInfo hospitalDoctorInfo1 = new HospitalDoctorInfo();
        int i = 0;
        int j = 0;
        for (HospitalDoctorInfo doctorInfo : hospitalDoctorInfos) {
            if(doctorInfo.getDoctorPassword().equals(hospitalDoctorInfo.getDoctorPassword())){
                j++;
                hospitalDoctorInfo1=doctorInfo;
            }
            i++;
        }
        if(i==0){
            return R.fail("用户名错误");
        }else {
            if(j==0){
                return R.fail("密码错误");
            }else {
                return R.ok(hospitalDoctorInfo1,"登录成功");
            }
        }

    }

    @Override
    public Result updInfo(Long doctorId, int doctorInquiryStatus) {
        int i = hospitalDoctorInfoMapper.updInfo(doctorId, doctorInquiryStatus);
        if (i>=1){
            return new Result(ResultCode.Ok,"修改成功");
        }else{
            return new Result(ResultCode.No,"修改失败");
        }
    }
}
